﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Smled.States
{
    class ManagedBrushState : BaseState
    {
        private ManagedBrushToolbar tbar = null;
        private int oldX = 0, oldY = 0;

        public ManagedBrushState(MapView mapv) : base(mapv)
        {
            tbar = new ManagedBrushToolbar();
        }

        public override System.Windows.Forms.ToolStrip ToolBar
        {
            get
            {
                return tbar;
            }
        }

        public override void Activate()
        {
            tbar.RefreshList();
        }

        public override void MapView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (tbar.SelectedBrush != null && e.Button == mv.PrimaryButton)
            {
                tbar.SelectedBrush.PaintToMapView(mv, mv.SelectedX, mv.SelectedY);
                mv.Invalidate();
            }
            //oldX = mv.SelectedX;
            //oldY = mv.SelectedY;
        }

        public override void MapView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == mv.PrimaryButton && tbar.SelectedBrush != null)
            {
                if (mv.SelectedX != oldX && mv.SelectedY != oldY)
                {
                    tbar.SelectedBrush.PaintToMapView(mv, mv.SelectedX, mv.SelectedY);
                    //oldX = mv.SelectedX;
                    //oldY = mv.SelectedY;
                }
            }
        }
    }
}
